<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Auth;
class PublicController extends Controller
{
    //
    public function login(){

        return view('admin.public.login'); 	

    }
    
    public function check(Request $request){

    	
    	$this->validate($request,[

    		'username'=>'required|min:2|max:50',
    		'password'=>'required|min:6',
    		'captcha'=>'required|size:4|captcha',

    	]);
    	$data = $request->only(['username','password']);
    	$data['status']='2';
    	$result = Auth::guard('admin')->attempt($data,$request->get('online'));
    	if($result){
             
            return redirect('/admin/index/index');

        }else{

            return redirect('/admin/public/login')->withErrors([
                'loginError' =>'用户名或密码错误'
            ]);
        }
    }

    public function logout(){

        Auth::guard('admin')->logout();
        return redirect('/admin/public/login');
    }
   
}

